<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* 设置表格样式 */
        table {
            width: 50%;
            margin: 20px auto;
            border-collapse: collapse;
            border: 2px solid black;
        }
        th, td {
            border: 1px solid black;
            padding: 8px;
            text-align: center;
        }
        tr:nth-child(even) {
            background-color: #f2f2f2;
        }
        input[type="text"] {
            padding: 5px;
            width: 100px;
        }
        button {
            padding: 5px 10px;
        }
    </style>
</head>
<body>
    <div id="app">
        <h2>欢迎光临_vue开发的收银系统_水果店</h2>
        <table>
            <thead>
                <tr>苹果 10 ￥ / 斤，折扣 <8折></tr><br>
            </thead>
            <tbody>
                <tr>请输入要购买的斤数<input type="text" v-model.trim="weight"></tr><br>
                <tr><button @click="checkout">结账买单</button></tr><br>
                <tr>结账单：总价{{this.totalprice}}￥元 折后价：{{this.discountedPrice}}￥元 省了：{{this.savedAmount}}￥元</tr><br>
            </tbody>
        </table>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>
    <script>
        const app = new Vue({
            el:'#app',
            data:{
                weight:0,
                totalprice:'',
                discountedPrice: '',
                savedAmount: '',

            },

            methods:{
                checkout(){
                    this.totalprice = 10*this.weight,
                    this.discountedPrice = 10*this.weight*0.8,
                    this.savedAmount = 10*this.weight-10*this.weight*0.8
                }
            }
        })
    </script>
</body>
</html>